<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.8"></script>
    <title>vue5事件对象$event</title>
  </head>
  <body>
    <div id="app">
        <p>count的值是:{{ count }}</p>
        <!-- 如果按钮是偶数,则按钮背景变成红色 -->
        <!-- vue提供了一个内置对象,它是固定的$event 他就是原生事件e -->
        <button @click="add(1, $event)">+n</button>
    </div>

    <script>
      const vm = new Vue({
        el: "#app",
        data: {
            count:0
        },
        methods: {
            //事件默认带了e这个属性值  n,e为形参
            add(n, e){
                this.count+=n;
                if(this.count%2==0){
                    e.target.style.backgroundColor ='red';
                }else{
                    e.target.style.backgroundColor ='';
                }
            },
        },
      });
    </script>
  </body>
</html>
